gtk: Implement per-focus implicit grabs
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 31 Mar 2017 15:55:49 +0000 (17:55 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 25 May 2017 14:25:58 +0000 (16:25 +0200)
Unlike GTK+ grabs which are global to all/one device, the implicit grab
is per focus, which means each may have implicit grabs on different or
the same widget.

gtk/gtkmain.c
gtk/gtkwindow.c
gtk/gtkwindowprivate.h

index 8114ea8a17d7db022a86a82329aaf4fcfbf1f78c..80272b3b8708a79afa23a90c314a94b5363eda3d 100644 (file)
@@ -1505,6 +1505,9 @@ handle_pointing_event (GdkEvent *event)
       if (event->type == GDK_MOTION_NOTIFY || event->type == GDK_ENTER_NOTIFY)
         update_cursor (toplevel, device, target);
 
+      if (event->type == GDK_TOUCH_BEGIN)
+        gtk_window_set_pointer_focus_grab (toplevel, device, sequence, target);
+
       /* Let it take the effective pointer focus anyway, as it may change due
        * to implicit grabs.
        */
@@ -1512,6 +1515,13 @@ handle_pointing_event (GdkEvent *event)
       break;
     case GDK_BUTTON_PRESS:
     case GDK_BUTTON_RELEASE:
+      target = gtk_window_lookup_effective_pointer_focus_widget (toplevel,
+                                                                 device,
+                                                                 sequence);
+      gtk_window_set_pointer_focus_grab (toplevel, device, sequence,
+                                         event->type == GDK_BUTTON_PRESS ?
+                                         target : NULL);
+      break;
     case GDK_SCROLL:
     case GDK_TOUCHPAD_PINCH:
     case GDK_TOUCHPAD_SWIPE:
index 56082ca74acd7d4d7a2012980b978d464b6836e2..9e8221e7ff5890a52cad9534455c268c00f01340 100644 (file)
@@ -11484,3 +11484,16 @@ gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
         }
     }
 }
+
+void
+gtk_window_set_pointer_focus_grab (GtkWindow        *window,
+                                   GdkDevice        *device,
+                                   GdkEventSequence *sequence,
+                                   GtkWidget        *grab_widget)
+{
+  GtkPointerFocus *focus;
+
+  focus = gtk_window_lookup_pointer_focus (window, device, sequence);
+  g_assert (focus != NULL);
+  gtk_pointer_focus_set_implicit_grab (focus, grab_widget);
+}
index 7f62cc7f38a88a23cb1fc9854bdb03b40558c768..7d8d18965d4e107f2830da8e914f2a3a9561f615 100644 (file)
@@ -153,6 +153,10 @@ void             gtk_window_update_pointer_focus (GtkWindow        *window,
                                                   GtkWidget        *target,
                                                   gdouble           x,
                                                   gdouble           y);
+void             gtk_window_set_pointer_focus_grab (GtkWindow        *window,
+                                                    GdkDevice        *device,
+                                                    GdkEventSequence *sequence,
+                                                    GtkWidget        *grab_widget);
 
 void             gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
                                                                   GtkWidget *widget);